package com.hxht.cmp.module;

import com.hxht.cmp.entity.User;
import com.hxht.cmp.service.StatisticalService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("judge_Info")
public class JudgeCountModule {
    @Autowired
    private StatisticalService statisticalService;

    /**
     * 跳转向法官开庭时长和开庭数页面
     *
     * @param courtUid
     * @param startDate
     * @param endDate
     * @return
     */
    @RequestMapping("judge_count_info")
    public ModelAndView judgeOpenInfo(String courtUid, String startDate, String endDate) {
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        if (ObjectUtils.isEmpty(courtUid)) {
            User user = (User) session.getAttribute("user");
            courtUid = user.getCourtUid();
        }
        List<Map<String, Object>> timeAndNumList = statisticalService.selectListJudgeOpenTimeAndOpenNum(courtUid, startDate, endDate);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("timeAndNumList", timeAndNumList);
        modelAndView.setViewName("count/judge_trial");
        return modelAndView;
    }
}